package com.sgcc.sx.pmos.e_sx_order.adapter;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.sx.pmos.e_sx_order.bean.AddSupplementContractItemBean;

public class AddSupplementContractItemAdapter extends BaseQuickAdapter
        <AddSupplementContractItemBean, BaseViewHolder> {


    public AddSupplementContractItemAdapter() {
        super(R.layout.item_add_supplement_contract);
    }


    @Override
    protected void convert(BaseViewHolder baseViewHolder, AddSupplementContractItemBean bean) {

        baseViewHolder.setText(R.id.tvMonth, bean.getMonth());
        EditText etData = baseViewHolder.getView(R.id.etData);

        etData.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    etData.addTextChangedListener(textWatcher);
                } else {
                    etData.removeTextChangedListener(textWatcher);
                }
            }

            TextWatcher textWatcher = new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                }

                @Override
                public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                }

                @Override
                public void afterTextChanged(Editable editable) {
                    bean.setValue(editable.toString().trim());
                }
            };
        });


    }
}
